#!/bin/sh
set -e

if [ ! -n "$CORELINK_ENV_TUYA_SDK_REALPATH" ]; then
    echo "请重新执行 env : source ./common/env.sh"
    exit 1
fi
./common/check_sdk_version.sh

# 若之前sdk编译过其他项目则还原
./common/check_project_path.sh $CORELINK_ENV_TUYA_PROJECT_REALPATH

#通过汇总文件夹拷贝到SDK
cp -rf ./diff/* $CORELINK_ENV_TUYA_SDK_REALPATH

#  设置vscode defines
./common/set_defines_vscode_properties.py ./.vscode/c_cpp_properties.json ./diff/apps/tuya.ai/demo_hub/app_default.config

# 切换到SDKAPP 路径
cd $CORELINK_ENV_TUYA_SDK_REALPATH/$CORELINK_ENV_TUYA_SDK_APP_PATH

tos.py build  & wait

if [ ! -d "$CORELINK_ENV_TUYA_PROJECT_REALPATH/output" ]; then
    mkdir $CORELINK_ENV_TUYA_PROJECT_REALPATH/output
fi
cp ./.build/bin/* -rf $CORELINK_ENV_TUYA_PROJECT_REALPATH/output/
